<template>
  <el-dropdown>
    <span class="el-dropdown-link">
      {{ name }}
      <el-avatar
        src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
      ></el-avatar>
      <el-icon class="el-icon--right">
        <arrow-down />
      </el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item icon="User">用户信息</el-dropdown-item>
        <el-dropdown-item icon="Tools">系统管理</el-dropdown-item>
        <el-dropdown-item icon="CloseBold" @click="handleLoginOut">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import localChe from '@/utils/cache'
import { useRouter } from 'vue-router'
import { useStore } from '@/store'

export default defineComponent({
  setup() {
    const router = useRouter()
    const store = useStore()
    const name = computed(() => store.state.login.userInfo.name)
    const handleLoginOut = () => {
      // 登出逻辑
      localChe.clearCache()
      router.push('/login')
    }
    return {
      name,
      handleLoginOut
    }
  }
})
</script>
<style lang="less" scoped>
.el-dropdown-link {
  cursor: pointer;
  // display: flex;
  // align-items: center;
  // justify-content: center;
}
</style>
